import 'dart:io';
import 'package:dio/dio.dart';
import 'extra_keys.dart';

/// oauth2.0 认证/授权 拦截器
class OauthInterceptor extends Interceptor {
  @override
  void onRequest(
    RequestOptions options,
    RequestInterceptorHandler handler,
  ) async {
    if (options.extra[ExtraKeys.needToken] == false) {
      return handler.next(options);
    }
    var tokenObj = "SpUtil.getObject(SPKeys.TOKEN_KEY)";
    options.headers[HttpHeaders.authorizationHeader] = "Bearer $tokenObj";
    return handler.next(options);
  }
}
